import type { FindLimitDto, FindList } from "./auth";

export enum StatusComment {
  Pass = "pass",
  Block = "block",
  Review = "review",
}

export interface Comment {
  id: number;
  ip: string;
  ua: string;
  avatar: string;
  email: string;
  name: string;
  replyName: string;
  replyEmail: string;
  status: string;
  suggestion: string;
  putTop: boolean;
  isAdmin: boolean;
  parent?: Comment;
  children?: Comment[];
  content: string;
  resourceId: string;
  createTime: Date;
  updateTime: Date;
}

export interface FindComment {
  id?: number;
  ip?: string;
  avatar?: string;
  email?: string;
  name?: string;
  replyName?: string;
  replyEmail?: string;
  status?: StatusComment;
  suggestion?: string;
  putTop?: boolean;
  isAdmin?: boolean;
  parent?: Comment | number;
  children?: Comment[] | number[];
  content?: string;
  resourceId?: string;
  createTime?: Date;
  updateTime?: Date;
}
export interface CreateCommentDto {
  ip?: string;
  ua: string;
  content: string;
  avatar: string;
  email: string;
  name: string;
  parent?: number;
  replyName?: string;
  replyEmail?: string;
  putTop?: boolean;
  suggestion?: string;
  pid?: string;
  status?: string;
  resourceId: string;
  isAdmin?: boolean;
}

export interface CommentQueryFind extends FindComment, FindLimitDto {}

export const findAll = (query?: CommentQueryFind) => {
  return useServerRequest<FindList<Comment>>("/comments", {
    method: "GET",
    params: { ...query },
  });
};

export const findByResourceId = (resourceId: string) => {
  return useServerRequest<Comment[]>(
    `/comments/findByResourceId/${resourceId}`,
    {
      method: "GET",
    }
  );
};

export const create = (data: CreateCommentDto) => {
  return useServerRequest("/comments", {
    method: "POST",
    body: { ...data },
  });
};
